package org.zoomdev.zoom.dao;

import org.zoomdev.zoom.common.expression.Symbol;

import java.util.Collection;

public interface Where<T extends Where> {

    T where(String key, Object value);

    T where(String key, Symbol symbol, Object value);

    T where(Condition condition);

    <E> T whereIn(String key, Collection<E> values);

    <E> T whereNotIn(String key, Collection<E> values);

    T whereNotNull(String key);

    T whereNull(String key);

    T like(String key, Like like, Object value);

    T orWhere(Condition condition);

    T orWhere(String key, Object value);

    T orLike(String key, Like like, Object value);


    T having(String key, Symbol symbol, Object value);

    enum Like {

        MATCH_BOTH("%%%s%%"),                //like '%{}%'
        MATCH_END("%%%s"),                //like '%{}'
        MATCH_START("%s%%");                //like '{}%'

        private final String format;

        Like(String format) {
            this.format = format;
        }

        public String toValue(Object value) {
            return String.format(format, value);
        }
    }


    interface Condition {
        void where(Where where);
    }

}
